package com.yaozheng.vocationaltraining.view;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.iview.IItemView;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.TypeUtils;
import com.yaozheng.vocationaltraining.widget.MemoryWealthStatisticsView;
import com.yaozheng.vocationaltraining.widget.MemoryWealthStatisticsView1;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 一项记忆财富(你该学习的内容)
 *
 * @author Administrator
 */
@EViewGroup(R.layout.item_memory_wealth)
public class MemoryWealthItemView extends LinearLayout {
    @ViewById
    TextView memoryWealthItemTitleText, memoryWealthItemLearningTimeText,
            memoryWealthItemlearningPointsText;
    @ViewById
    MemoryWealthStatisticsView1 memoryWealthItemStatisticsView;
    int position;
    IItemView iItemView;

    public void init(IItemView iItemView) {
        this.iItemView = iItemView;
    }


    public MemoryWealthItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MemoryWealthItemView(Context context) {
        super(context);
    }

    /**
     * 加载数据
     *
     * @param position
     */
    public void loadData(int position, JSONObject courseJsonObject) {
        System.out.println("---------" + courseJsonObject.toString());
        this.position = position;
        memoryWealthItemTitleText.setText(TypeUtils.getJsonString(
                courseJsonObject, "courseSubject"));
        memoryWealthItemLearningTimeText.setText("第一次学习时间："
                + TypeUtils.getJsonString(courseJsonObject, "learningTime"));
        memoryWealthItemlearningPointsText.setText("上次复习时间："
                + TypeUtils.getJsonString(courseJsonObject, "lastReviewTime"));
        memoryWealthItemStatisticsView.setDataValue(TypeUtils.getJsonArray(
                courseJsonObject, "learningPoints"));
    }

    /**
     * 复习点击
     */
    @Click(R.id.memoryWealthItemStatisticsView)
    public void reviewClick() {
        if (iItemView != null) {
            iItemView.itemClick(position);
        }

        // if (position % 2 == 0) {
        // Intent intent = new Intent();
        // intent.putExtra("title", "复习");
        // intent.setClassName(getContext(),
        // Constants.VIDEO_COURSEWARE_DETAIL_ACTIVITY_CLASS_NAME);
        // getContext().startActivity(intent);
        // } else {
        // Intent intent = new Intent();
        // intent.putExtra("title", "复习");
        // intent.setClassName(getContext(),
        // Constants.IMAGE_LIST_COURSEWARE_DETAIL_ACTIVITY_CLASS_NAME);
        // getContext().startActivity(intent);
        // }
    }
}
